<template>
  <view class="container">
    <z-paging-swiper>
      <view slot="top">
        <u-navbar height="50" title="退换货" title-size="36" title-color="#333"></u-navbar>
        <view class="tabsView">
          <!-- <u-tabs-swiper ref="uTabs" :list="tabsList" :current="current" @change="tabsChange"
						:is-scroll="false" :show-bar="false" active-color="#0F76BC" swiper-width="750">
					</u-tabs-swiper> -->
        </view>
        <u-gap height="20" bg-color="#F0F1F2"></u-gap>
      </view>
      <swiper
        class="swiperView"
        :current="scurrent"
        @transition="transition"
        @animationfinish="animationfinish"
      >
        <swiper-item class="swiperItem">
          <z-paging
            ref="paging"
            v-model="itemList"
            @query="queryList"
            :fixed="true"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view class="itemView" v-for="(item, index1) in itemList" :key="index1">
                <view class="order-top">
                  <view class=""> 店铺名称店铺名称店铺名称> </view>
                  <view v-if="item.status < 50" class="order-top-tip"> 待处理 </view>
                  <view v-else-if="item.status == 50" class="order-top-tip"> 退款成功 </view>
                  <view v-else-if="item.status == 61" class="order-top-tip"> 取消退款 </view>
                  <view v-else-if="item.status > 61" class="order-top-tip"> 退款失败 </view>
                </view>

                <view class="order-goods">
                  <u-icon class="goods-img" :name="item.picUrl" size="160"></u-icon>
                  <view class="orde-riget">
                    <view class="goods-title"> 产品名称餐品名称 </view>
                    <view class="goods-speci">
                      {{ item.properties[0].valueName }}
                      <text class="goods-num">x{{ item.count }}</text>
                    </view>
                    <view class="goods-price">
                      <!-- ¥88.60 -->
                    </view>
                  </view>
                </view>

                <!-- 实付金额¥690.00 &nbsp;&nbsp;&nbsp;&nbsp; -->
                <view class="price-total">
                  退款金额<text>¥{{ item.refundPrice }}</text>
                </view>
                <view v-if="item.status == 3" class="denial">
                  退款失败原因：因长时间未处理，本次申请已关闭
                </view>
                <view class="btn-group" v-if="item.status == 1">
                  <view class="hollow-btn btn" @click="routeTo(item)"> 查看详情 </view>
                  <view class="hollow-btn btn"> 撤销申请 </view>
                </view>
                <view class="btn-group" v-else>
                  <view class="hollow-btn btn" @click="routeTo(item)"> 查看详情 </view>
                  <!-- <view class="hollow-btn btn">
										删除记录
									</view> -->
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
        <!-- <swiper-item class="swiperItem">
					<z-paging ref="paging2" v-model="itemList2" @query="queryList2" :fixed="false" :auto="false"
						:empty-view-img="`${getImageUrl('empty.png')} `" empty-view-text="暂无订单数据~" :empty-view-img-style="imgStyle">

							<view class="goodsItemView">
								<view class="itemView" v-for="(item,index1) in itemList" :key="index1"
									@click="onOrderDetail(item)">
									<view class="order-top">
										<view class="">
											店铺名称店铺名称店铺名称>
										</view>
										<view  class="order-top-tip">
											待处理
										</view>
									</view>

									<view class="order-goods">
									   <u-icon class="goods-img" name="/static/img/gimg.png" size="160"></u-icon>
									   <view class="orde-riget">
											<view class="goods-title">
												产品名称餐品名称
											</view>
											<view class="goods-speci">
												规格
												<text class="goods-num">x10</text>
											</view>
											<view class="goods-price">
												¥88.60
											</view>
									   </view>
									</view>
									<view class="price-total">
										<view class="" style="float: left; display: flex; align-items: center;">
											<u-icon style="margin-right: 10rpx;" name="/static/img/tui1.png" size="40"></u-icon>退货
										</view>
										退款金额<text>¥{{item.refundPrice}}</text>
									</view>

									<view class="btn-group">
										<view class="hollow-btn btn" @click="routeTo(item)">
											查看详情
										</view>
										<view class="hollow-btn btn">
											撤销申请
										</view>
									</view>
								</view>
							</view>
					</z-paging>
				</swiper-item> -->
      </swiper>
    </z-paging-swiper>
  </view>
</template>

<script>
export default {
  data() {
    return {
      imgStyle: {
        width: '12rem'
      },
      current: 0,
      scurrent: 0,
      tabsList: [
        {
          name: '全部'
        },
        {
          name: '待处理'
        }
      ],
      itemList: [],
      itemList2: [{}],
      order_id: ''
    }
  },
  onLoad(res) {
    this.queryList(1)
  },
  onShow() {
    let self = this
    this.$nextTick(function () {
      //self.onOrderLoad(self.current, null, true);
    })
  },
  methods: {
    tabsChange(index) {
      this.scurrent = index
    },
    transition(e) {
      let dx = e.detail.dx
      this.$refs.uTabs.setDx(dx)
    },
    animationfinish(e) {
      this.current = e.detail.current
      this.scurrent = e.detail.current
      this.$refs.uTabs.setFinishCurrent(e.detail.current)
      this.queryList(1)
    },
    queryList(pageNo = 1, pageSize = 10) {
      if (pageNo === 1) {
        this.itemList = []
      }
      this.$u.get('/app-api/trade/after-sale/page', { pageNo, pageSize, id: '' }).then((res) => {
        //this.itemList = res.data.list
        this.$refs.paging.complete(res.data.list)
      })
    },

    onOrderCancel(item) {
      let self = this
      uni.dialog.confirm('温馨提示', '确定要取消订单吗？', () => {
        self.$u.api.setOrderCancel(item.id).then((res) => {
          self.$u.toast('取消成功')
          setTimeout(function () {
            self.onOrderLoad(self.current, null, true)
          }, 500)
        })
      })
    },
    onOrderPayment(item) {
      let self = this
      // self.$u.api.setTestPayments({
      // 	order_no: item.order_no,
      // 	openid: uni.getStorageSync('openid')
      // }).then(res => {
      // 	setTimeout(function() {
      // 		self.onOrderLoad(self.current, null, true);
      // 	}, 500);
      // });
      this.$utils.route({
        url: '/goods/payment/payment',
        params: {
          order_id: item.id,
          money: item.pay_price,
          total_weight: item.total_weight,
          delivery_price: item.delivery_price
        }
      })
    },
    onOrderConfrim(item) {
      let self = this
      uni.dialog.confirm('温馨提示', '该订单确认收货吗？', () => {
        self.$u.api.setOrderConfirm(item.id).then((res) => {
          self.$u.toast('收货成功')
          setTimeout(function () {
            self.onOrderLoad(self.current, null, true)
          }, 500)
        })
      })
    },
    onResellPush(item) {
      this.$utils.route({
        url: '/goods/resell-push/resell-push',
        params: {
          id: item.id
        }
      })
    },
    onPushComment(item) {
      this.$utils.route({
        url: '/other/push-comment/push-comment',
        params: {
          id: item.id
        }
      })
    },

    routeTo(item) {
      console.log(item)
      uni.navigateTo({
        url: '/other/after-sales/after-sales?status=1&id=' + item.id
      })
    }
  }
}
</script>

<style>
page {
  height: 100%;
  background: #f0f1f2;
}
.tabsView {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  height: 90rpx;
}

.goodsItemView {
  display: flex;
  flex-direction: column;
}

.itemView {
  display: flex;
  flex-direction: column;
  background-color: #ffffff;
  margin-bottom: 1rem;
  border-radius: 6px;
  padding: 20rpx;
}

.order-top {
  position: relative;
  padding: 15rpx 0;
  font-size: 30rpx;
}

.order-top-tip {
  position: absolute;
  top: 15rpx;
  right: 0;
  color: #999999;
}

.order-goods {
  display: flex;
}

.goods-img {
  border-radius: 20rpx;
}

.orde-riget {
  width: 100%;
  margin-left: 10rpx;
  line-height: 55rpx;
  font-size: 26rpx;
}

.goods-speci {
  position: relative;
}

.goods-num {
  position: absolute;
  top: 0;
  right: 0;
  color: #999999;
}
.goods-price {
  font-size: 30rpx;
  color: #f54831;
}
.price-total {
  padding: 20rpx 0;
  border-top: #ededed solid 2rpx;
  border-bottom: #ededed solid 2rpx;
  text-align: right;
  font-size: 28rpx;
  margin: 15rpx 0;
}

.btn-group {
  display: flex;
  flex-direction: row-reverse;
}

.btn {
  display: inline-block;
  padding: 15rpx 20rpx;
  border-radius: 35rpx;
  font-size: 28rpx;
  margin-left: 15rpx;
}
.hollow-btn {
  color: #666666;
  border: #e6e6e6 solid 2rpx;
}
.solid-btn {
  background-color: #0f76bc;
  color: #fff;
}

.denial {
  padding: 15rpx 0;
  color: #f54831;
}
</style>
